﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<!-- saved from url=(0048)http://topic.csdn.net/t/20060720/13/4893050.html -->
<HTML lang=zh-CN xml:lang="zh-CN" 
xmlns="http://www.w3.org/1999/xhtml"><HEAD>

<STYLE type=text/css>.pub_footerall {
	WIDTH: 770px
}
</STYLE>
<TITLE>c/c++ 如何读取windows xp的注册表。 C/C++ / C++ 语言 - CSDN社区 community.csdn.net</TITLE>
<META content=all name=robots>
<META http-equiv=Content-Language content=zh-CN>
<META http-equiv=Content-Type content="text/html; charset=utf-8"><LINK 
href="c-c++ 如何读取windows xp的注册表。 C-C++ - C++ 语言 - CSDN社区 community_csdn_net.files/topic.css" 
type=text/css rel=stylesheet>
<SCRIPT 
src="c-c++ 如何读取windows xp的注册表。 C-C++ - C++ 语言 - CSDN社区 community_csdn_net.files/Topic.js" 
type=text/javascript></SCRIPT>

<META content=" C/C++ C++ 语言" name=Keywords>
<META content=如题。如果可以，请提供标准库函数和使用说明。谢谢。 name=description>
<META content="MSHTML 6.00.2900.5945" name=GENERATOR></HEAD>
<BODY>
<DIV id=wrapper>
<DIV id=innerWrapper>
<DIV id=logo>
<SCRIPT 
src="c-c++ 如何读取windows xp的注册表。 C-C++ - C++ 语言 - CSDN社区 community_csdn_net.files/csdn_ggmm.js"></SCRIPT>

<SCRIPT type=text/javascript>show_ads_zone(230);</SCRIPT>
&nbsp;<DIV>
<DIV style="MARGIN: 0px auto; OVERFLOW: hidden; WIDTH: 100%">
<SCRIPT 
src="c-c++ 如何读取windows xp的注册表。 C-C++ - C++ 语言 - CSDN社区 community_csdn_net.files/pub_topnav.js" 
type=text/javascript></SCRIPT>
</DIV>
<DIV id=logo>
<SCRIPT type=text/javascript>setTimeout("document.getElementById('bigFlash').style.display='none'", 5000);</SCRIPT>
</DIV>
<TABLE>
  <TBODY>
  <TR>
    <TD>&nbsp;</TD>
    <TD>
      <SCRIPT type=text/javascript>show_ads_zone(228);</SCRIPT>
<!--<iframe frameborder="0" width="475" height="60" scrolling="no" src="/t/img/centerAd.htm">
    </iframe>--></TD>
    <TD>
      <SCRIPT type=text/javascript>show_ads_zone(229);</SCRIPT>
    </TD></TR></TBODY></TABLE><!-- script src="http://notify.hi.csdn.net/PromptInfo.ashx?ForWhat=FullJs"></script --><LINK 
media=all 
href="c-c++ 如何读取windows xp的注册表。 C-C++ - C++ 语言 - CSDN社区 community_csdn_net.files/csdn_favbykimi.css" 
type=text/css rel=stylesheet>
<DIV id=navigation>
<DIV id=search>
<DIV id=innerSearch><INPUT id=key onfocus="value=''"><A 
onclick="return Search()" 
href="http://topic.csdn.net/t/20060720/13/4893050.html#">搜索</A>&nbsp;<CITE 
class=fav_csdnstylebykimi><A title=收藏到我的网摘中，并分享给我的朋友 
href="javascript:d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(saveit=window.open('http://wz.csdn.net/storeit.aspx?t='+escape(d.title)+'&amp;u='+escape(d.location.href)+'&amp;c='+escape(t),'saveit','scrollbars=no,width=590,height=300,left=75,top=20,status=no,resizable=yes'));saveit.focus();">收藏</A></CITE>&nbsp;<A 
onclick="return Print()" 
href="http://topic.csdn.net/t/20060720/13/4893050.html#">打印</A>&nbsp;<A 
onclick="return Close()" 
href="http://topic.csdn.net/t/20060720/13/4893050.html#">关闭</A> </DIV></DIV>
<DIV><A class=CSDNRoom href="http://community.csdn.net/" 
rel=external>CSDN社区</A>&nbsp;&gt;&nbsp; <A 
href="http://community.csdn.net/Expert/ForumsList.asp?typenum=1&amp;roomid=56" 
rel=external>C/C++</A>&nbsp;&gt;&nbsp; <A 
href="http://community.csdn.net/Expert/ForumList.asp?typenum=1&amp;roomid=5604" 
rel=external>C++ 语言</A> </DIV></DIV>
<DIV id=mainWrapper>
<DIV id=pageContent>
<DIV id=innerContent>
<H1>c/c++ 如何读取windows xp的注册表。</H1>
<DIV class=author><A class=anchor name=Top>楼主</A>IaoapBicfisH（麟）<INPUT class=user1 title="一级用户 该版得分小于等于100分" type=button>2006-07-20 
13:19:39 在 C/C++ / C++ 语言 提问</DIV>
<P>如题。 &nbsp; <BR>&nbsp; 如果可以，请提供标准库函数和使用说明。谢谢。 <SPAN>问题点数：20、回复次数：5</SPAN><A 
href="http://topic.csdn.net/t/20060720/13/4893050.html#">Top</A> </P>
<DIV class=tagad>&nbsp;</DIV>
<H3><STRONG><A class=anchor name=r_35708700>1 楼</A>awl005（忽然）<INPUT class=user2 title="二级用户 该版得分小于等于500分，大于100分" type=button></STRONG><SPAN>回复于 
2006-07-20 13:54:13 得分 0 </SPAN></H3>
<P>给你贴一份抄来的API说明 &nbsp; <BR>&nbsp; &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; 
1·RegClose() &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; 原形：LONG &nbsp; RegCloseKey( 
&nbsp; &nbsp; HKEY &nbsp; hKey &nbsp; ); &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; 
返回值:不成功返回非0，成功返回ERROR_SUCCESS &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; 
解释：关闭指定的主册表键，释放句柄。当对一个或多个键或值操作完成以后，需要关闭其键来进行保存操作结果。关闭一个键后，句柄变为非法，以使其不可再次被使用。为系统重新使用而释放句柄。 
&nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; 2·RegCreateKeyEx()和RegCreateKey() 
&nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; 原形：LONG &nbsp; RegCreateKeyEx( &nbsp; 
&nbsp; &nbsp; &nbsp; HKEY &nbsp; hKey, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; // &nbsp; 主键名称 &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LPCTSTR &nbsp; lpSubKey, &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; // &nbsp; 子键名称或路径 &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DWORD &nbsp; Reserved, &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; // &nbsp; 保留，为0 &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LPTSTR &nbsp; lpClass, &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; // &nbsp; 没弄懂，我设为空也差不多 &nbsp; &nbsp; <BR>&nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DWORD &nbsp; dwOptions, 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* &nbsp; 
对你建立的键的一些选项，可以是这些值：REG_OPTION_NON_VOLATILE，REG_OPTION_VOLATILE，REG_OPTION_BACKUP_RESTORE第一个是默认的了。一般用第一个就可以了。*/ 
&nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
REGSAM &nbsp; samDesired, &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp; 设置你对你建立的这个键的访问权限 
&nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
LPSECURITY_ATTRIBUTES &nbsp; lpSecurityAttributes, &nbsp; &nbsp; <BR>&nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; //不太明白 &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; PHKEY &nbsp; phkResult, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
// &nbsp; 指向你建的句柄 &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; LPDWORD &nbsp; lpdwDisposition &nbsp; &nbsp; 
//用来查看是打开一个已经有的键，还是新建了键 &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; ); &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; 
RegCreateKey()函数简单了不少，请自己看了。 &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; 
返回值：不成功返回非0，成功返回ERROR_SUCCESS. &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; 
解释：打开指定的键或子键。如果要打开的键不存在的话，本函数会试图建立它。当在创建或打开注册表的键时，需要指定访问权限，而这些访问权限需要到一级。默认的权限是KEY_ALL_ACCESS权限。还有KEY_CREATE_LINK创建字符链权限,KEY_CREATE_SUB_KEY创建子键权限,KEY_EXECUTE读取键权限，KEY_NOTIFY获得修改键通知的权限，KEY_QUERY_VALUE查询键值的权限，KEY_SET_VALUE设置数据值的权限。注意不能在根一级建键，在注册表的根一级仅可有预定义的键。具体使用，请查看联机手册。 
&nbsp; &nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; 4·RegDeleteKey() &nbsp; 
&nbsp; <BR>&nbsp; &nbsp; &nbsp; 原形：LONG &nbsp; RegDeleteKey( &nbsp; &nbsp; 
<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HKEY &nbsp; 
hKey, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp; 已打开的键的句柄 &nbsp; &nbsp; 
<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LPCTSTR 
&nbsp; lpSubKey &nbsp; &nbsp; // &nbsp; 要删除的子键或路径，传如""将删除key本身 &nbsp; &nbsp; 
<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ); &nbsp; &nbsp; 
<BR>&nbsp; &nbsp; &nbsp; 返回值：不成功返回非0，成功返回ERROR_SUCCESS &nbsp; &nbsp; <BR>&nbsp; 
&nbsp; &nbsp; 
该函数用来删除注册表中的一个键值的。在用此函数时需要注意98与NT的差异。在NT中在删除一个键之前，要求必须删除所有子键，需要从下向上递归删除所有子键，而WINDOWS98没有他那么复杂，只要删除键及其所有子键就可以啦。 
&nbsp; &nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; 
5·RegQueryValue()和RegQueryValueEx() &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; 
原形：LONG &nbsp; RegQueryValueEx( &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HKEY &nbsp; hKey, &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; // &nbsp; 已打开的键的句柄 &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LPTSTR &nbsp; lpValueName, &nbsp; // &nbsp; 
要查询值的名称，传如""为查询键下的默认值 &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; LPDWORD &nbsp; lpReserved, &nbsp; // &nbsp; 保留，为0 
&nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
LPDWORD &nbsp; lpType, &nbsp; &nbsp; &nbsp; // &nbsp; 查询的类型 &nbsp; &nbsp; 
<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LPBYTE &nbsp; 
lpData, &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp; 数据存放的地址 &nbsp; &nbsp; <BR>&nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LPDWORD &nbsp; lpcbData 
&nbsp; &nbsp; &nbsp; // &nbsp; 数据长度+1 &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; ); &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; 
返回值：不成功返回非0，成功返回ERROR_SUCCESS &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; 
解释：读取某子键下特定名称的值。 &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; 例子 &nbsp; &nbsp; 
<BR>&nbsp; &nbsp; &nbsp; &nbsp; CString &nbsp; m_strQ;//用来存放查询来的字符串值 &nbsp; 
&nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; DWORD &nbsp; 
m_dwCount;//记录字符串的长度+1（包括NULL字符） &nbsp; &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; 
&nbsp; ::RegQueryValueEx(m_hkey,"",0,NULL,NULL,&amp;m_dwCount);//先查询出字节空间 &nbsp; 
&nbsp; &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; ret1=(::RegQueryValueEx 
&nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
(m_hkey,"",0,NULL,(unsigned &nbsp; char &nbsp; 
*)m_strQ.GetBuffer(m_dwCount),&amp;m_kk)); &nbsp; &nbsp; <BR>&nbsp; &nbsp; 
&nbsp; &nbsp; m_strQ.ReleaseBuffer(); &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; 
&nbsp; MessageBox(m_strQ); &nbsp; &nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; &nbsp; 
&nbsp; 6·RegSetValue()和RegSetValueEX() &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; 
原形：LONG &nbsp; RegSetValueEx( &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HKEY &nbsp; hKey, &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; // &nbsp; 已打开的键的句柄 &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LPCTSTR &nbsp; lpValueName, &nbsp; // &nbsp; 
要查询值的名称，传如""为查询键下的默认值 &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; DWORD &nbsp; Reserved, &nbsp; &nbsp; &nbsp; // 
&nbsp; 保留 &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; DWORD &nbsp; dwType, &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp; 变量的类型 
&nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
CONST &nbsp; BYTE &nbsp; *lpData, &nbsp; // &nbsp; 变量数据的地址 &nbsp; &nbsp; 
<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DWORD &nbsp; 
cbData &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp; 变量的长度 &nbsp; &nbsp; 
<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ); &nbsp; &nbsp; <BR>&nbsp; 
&nbsp; &nbsp; 返回值：不成功返回非0，成功返回ERROR_SUCCESS &nbsp; &nbsp; <BR>&nbsp; &nbsp; 
&nbsp; 解释：设置某子键下特定名称的值。 &nbsp; &nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; 
7·RegEnumValue() &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; 原形：LONG &nbsp; 
RegEnumValue( &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; HKEY &nbsp; hKey, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
// &nbsp; 要查询的已打开的键的句柄 &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; DWORD &nbsp; dwIndex, &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; // &nbsp; 读取名称的索引号 &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; LPTSTR &nbsp; lpValueName, &nbsp; &nbsp; &nbsp; // 
&nbsp; 返回所读取的名称 &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; LPDWORD &nbsp; lpcbValueName, &nbsp; // &nbsp; 
返回读取名称的长度，不含chr(0) &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; LPDWORD &nbsp; lpReserved, &nbsp; &nbsp; &nbsp; // &nbsp; 
保留，为0 &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; LPDWORD &nbsp; lpType, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp; 
返回所读取的数据类型 &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; LPBYTE &nbsp; lpData, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp; 
返回所读取的数据 &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; LPDWORD &nbsp; lpcbData &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp; 
返回所读取的数据长度 &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ); &nbsp; 
&nbsp; <BR>&nbsp; &nbsp; &nbsp; 返回值：不成功返回非0，成功返回ERROR_SUCCESS &nbsp; &nbsp; 
<BR>&nbsp; &nbsp; &nbsp; 解释：列出某Key的所有名称的值，变化索引即可遍历整个键下的名称和数据。 &nbsp; &nbsp; 
<BR>&nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; 8·RegDeleteValue() &nbsp; &nbsp; 
<BR>&nbsp; &nbsp; &nbsp; 原形：LONG &nbsp; RegDeleteValue( &nbsp; &nbsp; <BR>&nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HKEY &nbsp; hKey, &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp; 要删除的键的句柄 &nbsp; &nbsp; <BR>&nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LPCTSTR &nbsp; 
lpValueName &nbsp; &nbsp; // &nbsp; 要删除的名称 &nbsp; &nbsp; <BR>&nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ); &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; 
返回值：不成功返回非0，成功返回ERROR_SUCCESS &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; 
解释：删除某Key的某一名称 &nbsp; &nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; 
9·RegEnumKey()和RegEnumKeyEx() &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; 原形：LONG 
&nbsp; RegEnumKeyEx( &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; HKEY &nbsp; hKey, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 
&nbsp; 要列举的键的句柄 &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; DWORD &nbsp; dwIndex, &nbsp; &nbsp; &nbsp; // &nbsp; 索引 
&nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
LPTSTR &nbsp; lpName, &nbsp; &nbsp; &nbsp; // &nbsp; 子键的名称 &nbsp; &nbsp; 
<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LPDWORD 
&nbsp; lpcbName, &nbsp; &nbsp; // &nbsp; 子键名称的长度 &nbsp; &nbsp; <BR>&nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LPDWORD &nbsp; lpReserved, 
&nbsp; // &nbsp; 保留 &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; LPTSTR &nbsp; lpClass, &nbsp; &nbsp; &nbsp; // &nbsp; 
address &nbsp; of &nbsp; buffer &nbsp; for &nbsp; class &nbsp; string &nbsp; 
&nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
LPDWORD &nbsp; lpcbClass, &nbsp; // &nbsp; address &nbsp; for &nbsp; size &nbsp; 
of &nbsp; class &nbsp; buffer &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PFILETIME &nbsp; lpftLastWriteTime &nbsp; 
&nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; // &nbsp; address &nbsp; for &nbsp; time &nbsp; key &nbsp; 
last &nbsp; written &nbsp; to &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; ); &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; 
返回值：不成功返回非0，成功返回ERROR_SUCCESS &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; 
返回注册表键及其子键的详细信息。 &nbsp; &nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; 
10·RegQueryInfoKey() &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; 原形：LONG &nbsp; 
RegQueryInfoKey( &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; HKEY &nbsp; hKey, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; // &nbsp; 已打开的键的句柄 &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LPTSTR &nbsp; lpClass, &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; // &nbsp; 类型名称，仅使用于NT。若不使用则传入Null &nbsp; &nbsp; <BR>&nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LPDWORD &nbsp; 
lpcbClass, &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp; 类型名称的长度 &nbsp; &nbsp; 
<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LPDWORD 
&nbsp; lpReserved, &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp; 保留 &nbsp; &nbsp; 
<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LPDWORD 
&nbsp; lpcSubKeys, &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp; 返回子键的数目 &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; LPDWORD &nbsp; lpcbMaxSubKeyLen, &nbsp; // &nbsp; 返回最长的子键长度 &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; LPDWORD &nbsp; lpcbMaxClassLen, &nbsp; // &nbsp; 返回最长的类长度 &nbsp; &nbsp; 
&nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
LPDWORD &nbsp; lpcValues, &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp; 返回值的数目 &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; LPDWORD &nbsp; lpcbMaxValueNameLen, &nbsp; // &nbsp; 返回最长的值项名称的长度 
&nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
LPDWORD &nbsp; lpcbMaxValueLen, &nbsp; // &nbsp; 返回最长的值的长度 &nbsp; &nbsp; 
<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LPDWORD 
&nbsp; lpcbSecurityDescriptor, &nbsp; //返回安全描述，仅适用于 &nbsp; NT &nbsp; &nbsp; 
<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PFILETIME 
&nbsp; lpftLastWriteTime &nbsp; &nbsp; // &nbsp; 返回键最后被写入的时间，仅适用于 &nbsp; NT 
&nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ); &nbsp; &nbsp; 
<BR>&nbsp; &nbsp; &nbsp; 返回值：不成功返回非0，成功返回ERROR_SUCCESS &nbsp; &nbsp; <BR>&nbsp; 
&nbsp; &nbsp; 解释：返回注册表键的信息，包括类名、子键数量、最长子键名、值的数量、最长值数据、安全描述符的长度以及上一次写入的时间等。 
&nbsp; &nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; 11·RegLoadKey() &nbsp; 
&nbsp; <BR>&nbsp; &nbsp; &nbsp; 原形：LONG &nbsp; RegLoadKey( &nbsp; &nbsp; 
<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HKEY &nbsp; 
hKey, &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp; 打开的句柄 &nbsp; &nbsp; <BR>&nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LPCTSTR &nbsp; lpSubKey, 
&nbsp; //子键的路径 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; LPCTSTR &nbsp; lpFile &nbsp; &nbsp; // &nbsp; 要写入注册表信息的文件 &nbsp; &nbsp; 
<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ); &nbsp; &nbsp; <BR>&nbsp; 
&nbsp; &nbsp; 返回值：不成功返回非0，成功返回ERROR_SUCCESS &nbsp; &nbsp; <BR>&nbsp; &nbsp; 
&nbsp; 解释：从指定的文件恢复注册表键的子键信息到注册表。 &nbsp; &nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; 
&nbsp; &nbsp; 12·RegReplaceKey() &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; 原形：LONG 
&nbsp; RegReplaceKey( &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; HKEY &nbsp; hKey, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
// &nbsp; handle &nbsp; to &nbsp; open &nbsp; key &nbsp; &nbsp; <BR>&nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LPCTSTR &nbsp; lpSubKey, 
&nbsp; // &nbsp; address &nbsp; of &nbsp; name &nbsp; of &nbsp; subkey &nbsp; 
&nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
LPCTSTR &nbsp; lpNewFile, &nbsp; // &nbsp; 在替换前生成新的备份文件 &nbsp; &nbsp; <BR>&nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LPCTSTR &nbsp; lpOldFile 
&nbsp; // &nbsp; 需要覆盖上注册表的文件 &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; ); &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; 
返回值：不成功返回非0，成功返回ERROR_SUCCESS &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; 
解释：从指定的文件恢复注册表键的子键信息到注册表并替换原有的值，并生成新的备份文件 &nbsp; &nbsp; <BR>&nbsp; &nbsp; 
<BR>&nbsp; &nbsp; &nbsp; 13· &nbsp; RegSaveKey() &nbsp; &nbsp; <BR>&nbsp; &nbsp; 
&nbsp; LONG &nbsp; RegSaveKey( &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; HKEY &nbsp; hKey, &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp; 要保存的句柄 
&nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LPCTSTR &nbsp; 
lpFile, &nbsp; // &nbsp; 保存子键的文件 &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; LPSECURITY_ATTRIBUTES &nbsp; lpSecurityAttributes &nbsp; &nbsp; 
&nbsp; &nbsp; //不太懂 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ); &nbsp; 
&nbsp; <BR>&nbsp; &nbsp; &nbsp; 返回值：不成功返回非0，成功返回ERROR_SUCCESS &nbsp; &nbsp; 
<BR>&nbsp; &nbsp; &nbsp; 解释：保存键及其子键信息到指定的文件。 &nbsp; &nbsp; <BR>&nbsp; &nbsp; 
<BR>&nbsp; &nbsp; &nbsp; 14· &nbsp; RegConnectRegistry() &nbsp; &nbsp; 
<BR>&nbsp; &nbsp; &nbsp; 原形：LONG &nbsp; RegConnectRegistry( &nbsp; &nbsp; 
<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LPTSTR &nbsp; 
lpMachineName, &nbsp; //远程计算机的名称 &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HKEY &nbsp; hKey, &nbsp; &nbsp; &nbsp; &nbsp; 
// &nbsp; 预先注册的句柄 &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; PHKEY &nbsp; phkResult &nbsp; &nbsp; // &nbsp; 远程计算机上的句柄 
&nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ); &nbsp; &nbsp; 
<BR>&nbsp; &nbsp; &nbsp; 返回值：不成功返回非0，成功返回ERROR_SUCCESS &nbsp; &nbsp; <BR>&nbsp; 
&nbsp; &nbsp; 解释：连接到远程系统的注册表。 &nbsp; &nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; &nbsp; 
&nbsp; 15·RegNotifyChangeKeyValue() &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; 
当修改指定的注册表对象时提供通知。 &nbsp; &nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; 16· 
&nbsp; RegUnloadKey() &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; LONG &nbsp; 
RegUnLoadKey( &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HKEY 
&nbsp; hKey, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp; handle &nbsp; to 
&nbsp; open &nbsp; key &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; LPCTSTR &nbsp; lpSubKey &nbsp; &nbsp; // &nbsp; address &nbsp; of &nbsp; 
name &nbsp; of &nbsp; subkey &nbsp; to &nbsp; unload &nbsp; &nbsp; <BR>&nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; ); &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; 
返回值：不成功返回非0，成功返回ERROR_SUCCESS &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; 
删除注册表键及其所有的子键。 &nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; 作者：unknown &nbsp; 更新时间： 
&nbsp; 2005-05-05<A 
href="http://topic.csdn.net/t/20060720/13/4893050.html#">Top</A></P>
<H3><STRONG><A class=anchor name=r_35708821>2 楼</A>ykzhujiang（朱朱）<INPUT class=user5 title="五级用户 该版得分小于等于5000分，大于2000分" type=button></STRONG><SPAN>回复于 
2006-07-20 13:58:29 得分 0 </SPAN></H3>
<P>这个不属于标准C++的范畴，调用windows &nbsp; api即可 &nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; Win 
&nbsp; 95及NT的注册数据库(Registry)是系统中非常重要的组成部分。在Win32 &nbsp; 
API中有一组Reg函数来处理这些问题。其一般的读写过程如下： &nbsp; <BR>&nbsp; &nbsp; &nbsp; <BR>&nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; 1、使用RegOpenKeyEx或RegCreateKeyEx函数打开或创建一个键； &nbsp; 
&nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
2、如果上一步成功，使用RegQueryValueEx读取子键的值，使用RegSetValueEx设置子键值，使用RegEnumKey获得所有子键，使用RegDeleteKey删除一个键； 
&nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 3、完成操作后使用RegCloseKey关闭键。 
&nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
下面这段程序打开HKEY_CURRENT_USER\Software\Zeal &nbsp; SoftStudio\AskPro &nbsp; 
FTP\LastTime键，然后读取WOL子键的值。 &nbsp; &nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; HKEY &nbsp; hkey; &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; char &nbsp; sz[256]; &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; DWORD &nbsp; dwtype, &nbsp; sl &nbsp; = &nbsp; 256; &nbsp; &nbsp; 
<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; RegOpenKeyEx(HKEY_CURRENT_USER, &nbsp; &nbsp; <BR>&nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; "Software\\Zeal &nbsp; SoftStudio\\AskPro &nbsp; 
FTP\\LastTime", &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NULL, 
&nbsp; KEY_ALL_ACCESS, &nbsp; &amp;hkey); &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; RegQueryValueEx(hkey, &nbsp; "WOL", &nbsp; NULL, &nbsp; 
&amp;dwtype, &nbsp; (LPBYTE)sz, &nbsp; &amp;sl); &nbsp; &nbsp; <BR>&nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; RegCloseKey(hkey); &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; MFC程序可以使用CRegKey类读写注册表。VB中调用API的办法可以参考QA000226 &nbsp; 
"如何访问Windows系统注册表"。 &nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; 打开注册键 &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LONG &nbsp; 
RegOpenKeyEx( &nbsp; HKEY &nbsp; hKey, &nbsp; &nbsp; // &nbsp; handle &nbsp; to 
&nbsp; open &nbsp; key &nbsp; &nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; LPCTSTR &nbsp; lpSubKey, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp; address &nbsp; 
of &nbsp; name &nbsp; of &nbsp; subkey &nbsp; to &nbsp; open &nbsp; &nbsp; 
<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DWORD &nbsp; ulOptions, &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; // &nbsp; reserved &nbsp; =0 &nbsp; <BR>&nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; REGSAM &nbsp; samDesired, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp; security 
&nbsp; access &nbsp; mask &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
PHKEY &nbsp; phkResult &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp; address &nbsp; 
of &nbsp; handle &nbsp; to &nbsp; open &nbsp; key &nbsp; &nbsp; <BR>&nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; ); &nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; 例: &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HKEY &nbsp; hd; 
&nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hd=HKEY_LOCAL_MACHINE; &nbsp; 
<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; char* &nbsp; 
Regkeyname="SoftWare\\Xy123\\Poker\\"; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; LONG &nbsp; a=RegOpenKeyEx(hd,Regkeyname,0,KEY_READ,&amp;hd); &nbsp; 
&nbsp; &nbsp; //成功返回ERROR_SUCCESS,否则返回错误代码 &nbsp; <BR>&nbsp; &nbsp; &nbsp; 
<BR>&nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 关闭注册键 &nbsp; <BR>&nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; LONG &nbsp; RegCloseKey( &nbsp; HKEY &nbsp; hKey 
&nbsp; // &nbsp; handle &nbsp; to &nbsp; key &nbsp; to &nbsp; close &nbsp; ); 
&nbsp; <BR>&nbsp; 例: &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
RegCloseKey(HKEY_LOCAL_MACHINE); &nbsp; <BR>&nbsp; OR: &nbsp; &nbsp; 
RegCloseKey(hd); &nbsp; &nbsp; <BR>&nbsp; 建立注册键 &nbsp; <BR>&nbsp; LONG &nbsp; 
RegCreateKeyEx( &nbsp; HKEY &nbsp; hKey, &nbsp; // &nbsp; handle &nbsp; to 
&nbsp; an &nbsp; open &nbsp; key &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; LPCTSTR &nbsp; lpSubKey, &nbsp; // &nbsp; address &nbsp; of 
&nbsp; subkey &nbsp; name &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; DWORD &nbsp; Reserved, &nbsp; // &nbsp; reserved &nbsp; =0 &nbsp; 
<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LPTSTR &nbsp; lpClass, 
&nbsp; // &nbsp; address &nbsp; of &nbsp; class &nbsp; string &nbsp; &nbsp; 
<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DWORD &nbsp; dwOptions, 
&nbsp; // &nbsp; special &nbsp; options &nbsp; flag &nbsp; &nbsp; <BR>&nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; REGSAM &nbsp; samDesired, &nbsp; // 
&nbsp; desired &nbsp; security &nbsp; access &nbsp; &nbsp; <BR>&nbsp; &nbsp; 
<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LPSECURITY_ATTRIBUTES 
&nbsp; lpSecurityAttributes, &nbsp; // &nbsp; address &nbsp; of &nbsp; key 
&nbsp; security &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
structure &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
PHKEY &nbsp; phkResult, &nbsp; // &nbsp; address &nbsp; of &nbsp; buffer &nbsp; 
for &nbsp; opened &nbsp; handle &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; LPDWORD &nbsp; lpdwDisposition &nbsp; // &nbsp; address 
&nbsp; of &nbsp; disposition &nbsp; value &nbsp; buffer &nbsp; ); &nbsp; 
<BR>&nbsp; 例: &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; char &nbsp; *sclass=""; 
&nbsp; &nbsp; //类名指定为空 &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; DWORD &nbsp; 
nbf=0; &nbsp; &nbsp; &nbsp; &nbsp; 
//接受返回值,指明是建立新键还是打开已有的键.(经试验总是返回REG_OPENED_EXISTING_KEY. &nbsp; <BR>&nbsp; 
&nbsp; &nbsp; &nbsp; LONG &nbsp; 
II=RegCreateKeyEx(hd,Regkeyname,0,sclass,REG_OPTION_NON_VOLATILE, &nbsp; 
<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
KEY_READ|KEY_WRITE,NULL,&amp;hd,&amp;nbf); &nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; 
//REG_OPTION_NON_VOLATILE &nbsp; 指明键永久保留.安全结构指明NULL,自动获得一默认值 &nbsp; <BR>&nbsp; 
//成功返回ERROR_SUCCESS,否则返回错误代码 &nbsp; &nbsp; <BR>&nbsp; 枚举键值 &nbsp; <BR>&nbsp; 
LONG &nbsp; RegEnumValue( &nbsp; HKEY &nbsp; hKey, &nbsp; // &nbsp; handle 
&nbsp; to &nbsp; key &nbsp; to &nbsp; query &nbsp; &nbsp; <BR>&nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DWORD &nbsp; dwIndex, &nbsp; // &nbsp; index 
&nbsp; of &nbsp; value &nbsp; to &nbsp; query &nbsp; &nbsp; <BR>&nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LPTSTR &nbsp; lpValueName, &nbsp; // &nbsp; 
address &nbsp; of &nbsp; buffer &nbsp; for &nbsp; value &nbsp; string &nbsp; 
&nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LPDWORD &nbsp; 
lpcbValueName, &nbsp; // &nbsp; address &nbsp; for &nbsp; size &nbsp; of &nbsp; 
value &nbsp; buffer &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; LPDWORD &nbsp; lpReserved, &nbsp; // &nbsp; reserved &nbsp; =NULL &nbsp; 
<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LPDWORD &nbsp; lpType, 
&nbsp; // &nbsp; address &nbsp; of &nbsp; buffer &nbsp; for &nbsp; type &nbsp; 
code &nbsp; &nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; LPBYTE &nbsp; lpData, &nbsp; // &nbsp; address &nbsp; of &nbsp; 
buffer &nbsp; for &nbsp; value &nbsp; data &nbsp; &nbsp; <BR>&nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LPDWORD &nbsp; lpcbData &nbsp; // &nbsp; 
address &nbsp; for &nbsp; size &nbsp; of &nbsp; data &nbsp; buffer); &nbsp; 
<BR>&nbsp; 例: &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; DWORD &nbsp; dinx=0; &nbsp; 
<BR>&nbsp; &nbsp; &nbsp; &nbsp; char &nbsp; valuename[70]; &nbsp; &nbsp; 
//分配数值名称缓冲区 &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
strcpy(valuename,"DeskPattern"); &nbsp; &nbsp; //随便指定哪个键值名 &nbsp; <BR>&nbsp; 
&nbsp; &nbsp; &nbsp; DWORD &nbsp; nsize=69; &nbsp; &nbsp; //数值名称缓冲区大小 &nbsp; 
<BR>&nbsp; &nbsp; &nbsp; &nbsp; DWORD &nbsp; k=REG_SZ; &nbsp; &nbsp; //指明数据类型 
&nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; unsigned &nbsp; char &nbsp; vari[70]; 
&nbsp; //分配数值缓冲区 &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; DWORD &nbsp; ncbvari=69; 
&nbsp; //数值缓冲区大小 &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; dinx=0; &nbsp; //从0开始 
&nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
while((II=RegEnumValue(hd,dinx,valuename,&amp;nsize,NULL,&amp;k,vari,&amp;ncbvari)) 
&nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; != &nbsp; ERROR_NO_MORE_ITEMS) &nbsp; <BR>&nbsp; &nbsp; &nbsp; 
&nbsp; { &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
dinx++;//索引 &nbsp; +1,准备取下一个值 &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; nsize=69; &nbsp; //恢复原来大小 &nbsp; <BR>&nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ncbvari=69; &nbsp; <BR>&nbsp; &nbsp; &nbsp; 
&nbsp; } &nbsp; <BR>&nbsp; 成功后返回值0,各变量返回后设置如下: &nbsp; <BR>&nbsp; 
valuename=数值名称,以0结尾;如 &nbsp; : &nbsp; DeskColor &nbsp; <BR>&nbsp; nsize=数值名称长度, 
&nbsp; 9 &nbsp; <BR>&nbsp; k=REG_SZ &nbsp; &nbsp; DeskColor &nbsp; 的类型为 &nbsp; 
REG_SZ &nbsp; <BR>&nbsp; vari=键值,32768 &nbsp; DeskColor="32768", &nbsp; 
<BR>&nbsp; ncbvari=键值长度 &nbsp; REG_SZ包括结尾0,=6, &nbsp; &nbsp; <BR>&nbsp; 读取键值 
&nbsp; <BR>&nbsp; LONG &nbsp; RegQueryValueEx( &nbsp; HKEY &nbsp; hKey, &nbsp; 
// &nbsp; handle &nbsp; to &nbsp; key &nbsp; to &nbsp; query &nbsp; &nbsp; 
<BR>&nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
LPTSTR &nbsp; lpValueName, &nbsp; // &nbsp; address &nbsp; of &nbsp; name &nbsp; 
of &nbsp; value &nbsp; to &nbsp; query &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LPDWORD &nbsp; lpReserved, &nbsp; // &nbsp; 
reserved &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; LPDWORD &nbsp; lpType, &nbsp; // &nbsp; address &nbsp; of &nbsp; buffer 
&nbsp; for &nbsp; value &nbsp; type &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LPBYTE &nbsp; lpData, &nbsp; // &nbsp; 
address &nbsp; of &nbsp; data &nbsp; buffer &nbsp; &nbsp; <BR>&nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LPDWORD &nbsp; lpcbData &nbsp; // 
&nbsp; address &nbsp; of &nbsp; data &nbsp; buffer &nbsp; size &nbsp; ); &nbsp; 
<BR>&nbsp; 例: &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
RegQueryValueEx(hd,valuename,NULL,&amp;k,vari,&amp;ncbvari); &nbsp; <BR>&nbsp; 
变量定义及成功后各变量设置值同RegEnumValueEx &nbsp; &nbsp; <BR>&nbsp; 写键值 &nbsp; <BR>&nbsp; 
LONG &nbsp; RegSetValueEx( &nbsp; HKEY &nbsp; hKey, &nbsp; // &nbsp; handle 
&nbsp; to &nbsp; key &nbsp; to &nbsp; set &nbsp; value &nbsp; for &nbsp; &nbsp; 
<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LPCTSTR &nbsp; 
lpValueName, &nbsp; // &nbsp; name &nbsp; of &nbsp; the &nbsp; value &nbsp; to 
&nbsp; set &nbsp; &nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; DWORD &nbsp; Reserved, &nbsp; // &nbsp; reserved 
&nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DWORD 
&nbsp; dwType, &nbsp; // &nbsp; flag &nbsp; for &nbsp; value &nbsp; type &nbsp; 
&nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CONST &nbsp; 
BYTE &nbsp; *lpData, &nbsp; // &nbsp; address &nbsp; of &nbsp; value &nbsp; data 
&nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DWORD 
&nbsp; cbData &nbsp; // &nbsp; size &nbsp; of &nbsp; value &nbsp; data &nbsp; ); 
&nbsp; <BR>&nbsp; 例: &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
strcpy(valuename,"Hello"); &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; unsigned 
&nbsp; char &nbsp; vari[10]; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; DWORD &nbsp; 
k=REG_SZ; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; strcpy((char*)vari,"1234567") 
&nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; RegSetValueEx(hd,valuename,0,k,vari,7); 
&nbsp; <BR>&nbsp; 成功后在Poker下增加一个键值 &nbsp; Hello &nbsp; : &nbsp; REG_SZ &nbsp; : 
&nbsp; 1234567 &nbsp; <BR>&nbsp; 写整型变量： &nbsp; <BR>&nbsp; int &nbsp; hi=8; 
&nbsp; <BR>&nbsp; RegSetValueEx(pj,valuename,0,REG_BINARY,(unsigned &nbsp; 
char*)&amp;hi,sizeof(int)); &nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; 成功后在Poker下增加一个键值 
&nbsp; Hello2 &nbsp; : &nbsp; REG_BINARY &nbsp; :08 &nbsp; 00 &nbsp; 00 &nbsp; 
00 &nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; void 
&nbsp; AddEventSource() &nbsp; <BR>&nbsp; { &nbsp; <BR>&nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; HKEY &nbsp; hk; &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; DWORD &nbsp; dwData; &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
UCHAR &nbsp; szBuf[80]; &nbsp; &nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; // &nbsp; Add &nbsp; your &nbsp; source &nbsp; name &nbsp; as 
&nbsp; a &nbsp; subkey &nbsp; under &nbsp; the &nbsp; Application &nbsp; &nbsp; 
<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp; key &nbsp; in &nbsp; the &nbsp; 
EventLog &nbsp; registry &nbsp; key. &nbsp; &nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; if &nbsp; (RegCreateKey(HKEY_LOCAL_MACHINE, &nbsp; 
&nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; "SYSTEM\\CurrentControlSet\\Services\ &nbsp; &nbsp; 
<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; \\EventLog\\Application\\SamplApp", &nbsp; &amp;hk)) &nbsp; &nbsp; 
<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
ErrorExit("Could &nbsp; not &nbsp; create &nbsp; the &nbsp; registry &nbsp; 
key."); &nbsp; &nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
// &nbsp; Set &nbsp; the &nbsp; name &nbsp; of &nbsp; the &nbsp; message &nbsp; 
file. &nbsp; &nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
strcpy(szBuf, &nbsp; "%SystemRoot%\\System\\SamplApp.dll"); &nbsp; &nbsp; 
<BR>&nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp; Add &nbsp; 
the &nbsp; name &nbsp; to &nbsp; the &nbsp; EventMessageFile &nbsp; subkey. 
&nbsp; &nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if &nbsp; 
(RegSetValueEx(hk, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp; subkey &nbsp; handle &nbsp; &nbsp; 
<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; "EventMessageFile", &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; // &nbsp; value &nbsp; name &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0, &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 
&nbsp; must &nbsp; be &nbsp; zero &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; REG_EXPAND_SZ, 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; // &nbsp; value &nbsp; type &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (LPBYTE) &nbsp; 
szBuf, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; // &nbsp; pointer &nbsp; to &nbsp; value &nbsp; data &nbsp; &nbsp; 
<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; strlen(szBuf) &nbsp; + &nbsp; 1)) &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; // &nbsp; length &nbsp; of &nbsp; value &nbsp; data &nbsp; 
&nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; ErrorExit("Could &nbsp; not &nbsp; set &nbsp; the &nbsp; event 
&nbsp; message &nbsp; file."); &nbsp; &nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; // &nbsp; Set &nbsp; the &nbsp; supported &nbsp; event 
&nbsp; types &nbsp; in &nbsp; the &nbsp; TypesSupported &nbsp; subkey. &nbsp; 
&nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dwData &nbsp; = 
&nbsp; EVENTLOG_ERROR_TYPE &nbsp; | &nbsp; EVENTLOG_WARNING_TYPE &nbsp; | &nbsp; 
&nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
EVENTLOG_INFORMATION_TYPE; &nbsp; &nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; if &nbsp; (RegSetValueEx(hk, &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; // &nbsp; subkey &nbsp; handle &nbsp; &nbsp; <BR>&nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
"TypesSupported", &nbsp; &nbsp; // &nbsp; value &nbsp; name &nbsp; &nbsp; 
<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; 0, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp; must &nbsp; be 
&nbsp; zero &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; REG_DWORD, &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp; value &nbsp; type &nbsp; &nbsp; 
<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; (LPBYTE) &nbsp; &amp;dwData, &nbsp; &nbsp; // &nbsp; pointer 
&nbsp; to &nbsp; value &nbsp; data &nbsp; &nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; sizeof(DWORD))) &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp; length &nbsp; of 
&nbsp; value &nbsp; data &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; ErrorExit("Could &nbsp; not &nbsp; set &nbsp; the 
&nbsp; supported &nbsp; types."); &nbsp; &nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; RegCloseKey(hk); &nbsp; &nbsp; <BR>&nbsp; } &nbsp; 
&nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; 
以下代码把注册表自启动shell的键值改写为C:\DK1\ATM\HARP\ExAtmShell.exe: &nbsp; <BR>&nbsp; &nbsp; 
<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HKEY 
&nbsp; hkey; &nbsp; <BR>&nbsp; LONG &nbsp; res; &nbsp; &nbsp; <BR>&nbsp; DWORD 
&nbsp; datatype=REG_SZ; &nbsp; &nbsp; <BR>&nbsp; unsigned &nbsp; char &nbsp; 
szvalue[_MAX_PATH]; &nbsp; <BR>&nbsp; 
strcpy((char*)szvalue,"C:\\DK1\\ATM\\HARP\\ExAtmShell.exe"); &nbsp; <BR>&nbsp; 
&nbsp; <BR>&nbsp; res &nbsp; =::RegOpenKeyEx(HKEY_LOCAL_MACHINE, &nbsp; &nbsp; 
<BR>&nbsp; "SOFTWARE\\Microsoft\\Windows &nbsp; NT\\CurrentVersion\\Winlogon\\", 
&nbsp; 0, &nbsp; &nbsp; <BR>&nbsp; KEY_WRITE|KEY_READ, &nbsp; &amp;hkey); &nbsp; 
&nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; if(res!=ERROR_SUCCESS) &nbsp; <BR>&nbsp; { 
&nbsp; <BR>&nbsp; AfxMessageBox("aaa"); &nbsp; <BR>&nbsp; return; &nbsp; 
<BR>&nbsp; } &nbsp; <BR>&nbsp; res &nbsp; = &nbsp; ::RegSetValueEx(hkey, &nbsp; 
"Shell", &nbsp; 0, &nbsp; datatype, &nbsp; szvalue, &nbsp; 
strlen(LPCSTR(szvalue))); &nbsp; &nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; 
RegCloseKey(hkey); &nbsp; <BR>&nbsp; if(res==ERROR_SUCCESS) &nbsp; <BR>&nbsp; 
::AfxMessageBox("你已经成功地将注册表自启动shell的键值设置为C:\\DK1\\ATM\\HARP\\ExAtmShell.exe"); 
&nbsp; <BR>&nbsp; else &nbsp; <BR>&nbsp; ::AfxMessageBox("设定失败:目标位置不存在这样的键!");<A 
href="http://topic.csdn.net/t/20060720/13/4893050.html#">Top</A></P>
<H3><STRONG><A class=anchor name=r_35710861>3 楼</A>corrupt（喜欢 睡在床板下 的思考）<INPUT class=user5 title="五级用户 该版得分小于等于5000分，大于2000分" type=button></STRONG><SPAN>回复于 
2006-07-20 15:09:23 得分 0 </SPAN></H3>
<P>api &nbsp; 有这个功能，<A 
href="http://topic.csdn.net/t/20060720/13/4893050.html#">Top</A></P>
<H3><STRONG><A class=anchor name=r_40235699>4 楼</A>beaver2008（海狸）<INPUT class=user1 title="一级用户 该版得分小于等于100分" type=button></STRONG><SPAN>回复于 
2007-04-12 11:42:41 得分 0 </SPAN></H3>
<P>怎么没有如何删除注册表内容？要删注册表键值前是不是需要打开？我想程序删除windows2000注册表中USB盘插拔记录的选项该怎么做？<A 
href="http://topic.csdn.net/t/20060720/13/4893050.html#">Top</A></P>
</DIV></DIV></DIV></DIV></DIV></DIV></DIV></BODY></HTML>
